<?php
namespace app\api\controller;
use app\common\util\AuthUtil;

/**
 * 接口基类
 * @author xiegaolei
 *
 */
class Test
{	
     public function index(){
     	$data = array();
     	$param = input ( "param." );
     	$data['token'] = $param['token'];
     	unset($param['signature']);
     	if (isset($param['data'])){
     		foreach ($param['data']['key'] as $k => $v){
     			if ($v){
     				$data[$v] = $param['data']['value'][$k];
     			}
     		}
     	}
     	 
     	//数组排序
     	ksort($data);
     	$str = to_url_params($data);
     	$signature = md5 ( sha1 ( $str ) . config( "system.app_sign_key" ) );
     	ajax_return_ok(['sign'=>$signature]);
     }
    
     public function getdata(){
     	
     	$data = array();
     	$param = input ( "param." );
     	$url = $param['url'];
     	$api = $param['api'];
     	if (empty($url) || empty($api)){
     		ajax_return_error('请填写接口地址');
     	}else{
     		$url = $url.$api;
     	}
     	
     	
     	$data['token'] = $param['token'];
     	$data['signature'] = $param['signature'];
     	if (isset($param['data'])){
     		foreach ($param['data']['key'] as $k => $v){
     			if ($v){
     				$data[$v] = $param['data']['value'][$k];
     			}
     		}
     	}
     	
     	switch ($param['method']){
     		case 'POST' : 
     			$result = curl_post($url, $data);
     			break;
     		case 'GET' :
     			$result = curl_get($url, $data);
     			break;
     		default:
     			$result = '';
     			break;
     		
     	}
     	
     	echo $result;
     	
     }
     
     public function gettoken(){
     	
     	$token =  createRandomCode(10);
     	ajax_return_ok(['token'=>$token]);
     }
     
    
    
}
